package smartlifev30.com.sdk.api.service_app;

import android.support.annotation.NonNull;

import smartlifev30.com.sdk.util.JsonUtil;
import smartlifev30.com.sdk.api.CallBack;
import smartlifev30.com.sdk.bean.request.BindGatewayRequest;
import smartlifev30.com.sdk.bean.request.EditGatewayRequest;
import smartlifev30.com.sdk.bean.request.ListGatewayRequest;
import smartlifev30.com.sdk.bean.request.UnbindGatewayRequest;
import smartlifev30.com.sdk.bean.response.LoginResponse;
import smartlifev30.com.sdk.net.baiwei.NetManager;

/**
 * Created by tys on 2018/8/12.
 */

public class GatewayMgmtImpl implements IGatewayMgmt {

    @Override
    public void listGateway(@NonNull String userName, @NonNull String token, @NonNull CallBack<LoginResponse> callback) {
        ListGatewayRequest listGatewayRequest = new ListGatewayRequest();
        listGatewayRequest.setFrom(userName);
        listGatewayRequest.setMsg_id(callback.getMsgId());
        listGatewayRequest.setMsg_class("gwapp_mgmt");
        listGatewayRequest.setMsg_name("gwapp_query_token");
        listGatewayRequest.setMsg_type("get");
        listGatewayRequest.setToken(token);
        NetManager.getInstance().sendMessage(JsonUtil.toString(listGatewayRequest));
    }

    @Override
    public void bindGateway(@NonNull String userName, @NonNull String token, @NonNull String sn, @NonNull CallBack<LoginResponse> callback) {
        BindGatewayRequest bindGatewayRequest = new BindGatewayRequest();
        bindGatewayRequest.setFrom(userName);
        bindGatewayRequest.setMsg_id(callback.getMsgId());
        bindGatewayRequest.setMsg_class("gwapp_mgmt");
        bindGatewayRequest.setMsg_name("gwapp_bind");
        bindGatewayRequest.setMsg_type("get");
        bindGatewayRequest.setToken(token);
        bindGatewayRequest.setUser(bindGatewayRequest.new User(sn));
        NetManager.getInstance().sendMessage(JsonUtil.toString(bindGatewayRequest));
    }

    @Override
    public void editGateway(@NonNull String userName, @NonNull String token, @NonNull String sn, @NonNull String alias, @NonNull CallBack<LoginResponse> callback) {
        EditGatewayRequest editGatewayRequest = new EditGatewayRequest();
        editGatewayRequest.setFrom(userName);
        editGatewayRequest.setMsg_id(callback.getMsgId());
        editGatewayRequest.setMsg_class("gwapp_mgmt");
        editGatewayRequest.setMsg_name("gwapp_edit");
        editGatewayRequest.setMsg_type("get");
        editGatewayRequest.setToken(token);
        editGatewayRequest.setGateway(editGatewayRequest.new Gateway(sn, alias));
        NetManager.getInstance().sendMessage(JsonUtil.toString(editGatewayRequest));
    }

    @Override
    public void unbindGateway(@NonNull String userName, @NonNull String token, @NonNull String sn, @NonNull CallBack<LoginResponse> callback) {
        UnbindGatewayRequest unbindGatewayRequest = new UnbindGatewayRequest();
        unbindGatewayRequest.setFrom(userName);
        unbindGatewayRequest.setMsg_id(callback.getMsgId());
        unbindGatewayRequest.setMsg_class("gwapp_mgmt");
        unbindGatewayRequest.setMsg_name("gwapp_unbind");
        unbindGatewayRequest.setMsg_type("get");
        unbindGatewayRequest.setToken(token);
        unbindGatewayRequest.setUser(unbindGatewayRequest.new User(sn));
        NetManager.getInstance().sendMessage(JsonUtil.toString(unbindGatewayRequest));
    }

}
